//
//  AppDelegate.m
//  CarsHome
//
//  Created by dapeng on 15/12/1.
//  Copyright © 2015年 dapeng. All rights reserved.
//

#import "AppDelegate.h"
#import "Theme-PrefixHeader.pch"
#import "ConfigurationTheme.h"

@interface AppDelegate ()

@property (nonatomic, retain) BaseNavigationController *viewNav;
@property (nonatomic, retain) BaseNavigationController *forumNav;
@property (nonatomic, retain) BaseNavigationController *findCarNav;
@property (nonatomic, retain) BaseNavigationController *findNav;
@property (nonatomic, retain) BaseNavigationController *mineNav;

@end

@implementation AppDelegate
- (void)dealloc {
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];

    self.window.backgroundColor = [UIColor whiteColor];
    

    _viewCon = [[ViewController alloc] init];
    self.viewNav = [[BaseNavigationController alloc] initWithRootViewController:_viewCon];
        [self setTabBarItem:_viewCon Title:@"" withTitleSize:13.0 andFoneName:@"Marion-Italic" selectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"tuijian_selected"] withTitleColor:RGB(21, 95, 216, 1.0f)unselectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"tuijian"] withTitleColor:RGB(108, 108, 108, 1.0f)];
    //论坛控制器
    _forum = [[ForumViewController alloc] init];
    self.forumNav = [[BaseNavigationController alloc] initWithRootViewController:_forum];
        [self setTabBarItem:_forum Title:@"" withTitleSize:13.0 andFoneName:@"Marion-Italic" selectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"luntan_selected"] withTitleColor:RGB(21, 95, 216, 1.0f)unselectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"luntan"] withTitleColor:RGB(108, 108, 108, 1.0f)];
    //找车控制器
    _findCar = [[FindCarViewController alloc] init];
    self.findCarNav = [[BaseNavigationController alloc] initWithRootViewController:_findCar];
        [self setTabBarItem:_findCar Title:@"" withTitleSize:13.0 andFoneName:@"Marion-Italic" selectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"zhaoche_selected"] withTitleColor:RGB(21, 95, 216, 1.0f)unselectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"zhaoche"] withTitleColor:RGB(108, 108, 108, 1.0f)];
    //发现控制器
    _find = [[FindViewController alloc] init];
    self.findNav = [[BaseNavigationController alloc] initWithRootViewController:_find];
        [self setTabBarItem:_find Title:@"" withTitleSize:13.0 andFoneName:@"Marion-Italic" selectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"faxian_selected"] withTitleColor:RGB(21, 95, 216, 1.0f)unselectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"faxian"] withTitleColor:RGB(108, 108, 108, 1.0f)];
    //我的控制器
    _mine = [[MineViewController alloc] init];
    self.mineNav = [[BaseNavigationController alloc] initWithRootViewController:_mine];
        [self setTabBarItem:_mine Title:@"" withTitleSize:13.0 andFoneName:@"Marion-Italic" selectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"wo_selected"] withTitleColor:RGB(21, 95, 216, 1.0f)unselectedImage:[[ConfigurationTheme shareInstance] getThemeImageName:@"wo"] withTitleColor:RGB(108, 108, 108, 1.0f)];
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *result = [userDefaults valueForKey:@"userPassGuide"];
    if (![result isEqualToString:@"iiooi"]) {
         [userDefaults setObject:@"iiooi" forKey:@"userPassGuide"];
    
    //引导页
    NSArray *cover = @[@"", @"", @""];
    NSArray *bg = @[@"bg1.png", @"bg2.png", @"bg3.png"];
    SAPGuidePageViewController *guidePageVC = [[SAPGuidePageViewController alloc] initWithCoverImageNames:cover backgroundImageNames:bg];
        _window.rootViewController = guidePageVC;
        guidePageVC.delegate = self;
    }else {
    [BaseTabBarController sharedInstance].viewControllers = @[_viewNav, _forumNav, _findCarNav, _findNav, _mineNav];
    _window.rootViewController = [BaseTabBarController sharedInstance];
    }
    
    [_viewCon release];
    [_forum release];
    [_findCar release];
    [_find release];
    [_mine release];
    [_viewNav release];
    [_forumNav release];
    [_findCarNav release];
    [_findNav release];
    [_mineNav release];
    [UMSocialData setAppKey:@"566ac50867e58e722a005bbd"];
    
    return YES;
}
//改变主题的通知


- (void)click {
    [BaseTabBarController sharedInstance].viewControllers = @[_viewNav, _forumNav, _findCarNav, _findNav, _mineNav];
    _window.rootViewController = [BaseTabBarController sharedInstance];
}



- (void)setTabBarItem:(UIViewController *)tabbarItem
                Title:(NSString *)title
        withTitleSize:(CGFloat)size
          andFoneName:(NSString *)foneName
        selectedImage:(UIImage *)selectedImage
       withTitleColor:(UIColor *)selectColor
      unselectedImage:(UIImage *)unselectedImage
       withTitleColor:(UIColor *)unselectColor{
    
    //设置图片
    tabbarItem.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:[unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

    //未选中字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:unselectColor,NSFontAttributeName:[UIFont fontWithName:foneName size:size]} forState:UIControlStateNormal];
    
//    选中字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:selectColor,NSFontAttributeName:[UIFont fontWithName:foneName size:size]} forState:UIControlStateSelected];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
